package com.gsnd.briuppts.service.impl;

import cn.hutool.core.lang.generator.SnowflakeGenerator;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gsnd.briuppts.entity.Do.ManagerFenceHouseExtend;
import com.gsnd.briuppts.entity.ManagerFenceHouse;
import com.gsnd.briuppts.mapper.ManagerFenceHouseMapper;
import com.gsnd.briuppts.service.ManagerFHService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ManagerFHServiceImpl implements ManagerFHService {
    @Autowired
    ManagerFenceHouseMapper managerFenceHouseMapper;
    @Override
    public PageInfo<ManagerFenceHouse> findAllByConditionByPage(String fhName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ManagerFenceHouse> managerFenceHouses = managerFenceHouseMapper.selectAllCondition(fhName);
        PageInfo<ManagerFenceHouse> PageInfo = new PageInfo<>(managerFenceHouses);
        System.out.println(PageInfo);
        return PageInfo;
    }

    @Override
    public void addAndEdit(ManagerFenceHouse managerFenceHouse) {

        String fhId = managerFenceHouse.getFhId();
        if (StrUtil.isEmpty(fhId)){
            SnowflakeGenerator generator=new SnowflakeGenerator();
            Long snowId=generator.next();
            String fhNewId = String.valueOf((snowId));
            managerFenceHouse.setFhId(fhNewId);
            managerFenceHouse.setFhDelete(0);
            managerFenceHouseMapper.insert(managerFenceHouse);
        }else {
            managerFenceHouseMapper.updateSelective(managerFenceHouse);
        }

    }

    @Override
    public void removeByIdOrAll(List<String> fhIds) {
        managerFenceHouseMapper.logicDeleteBatch(fhIds);
    }

    @Override
    public ManagerFenceHouseExtend findDetailByFhId(String fhId) {
        return managerFenceHouseMapper.selectDeleteById(fhId);
    }

    @Override
    public List<ManagerFenceHouse> findAll()
    {
        return managerFenceHouseMapper.selectAll();
    }
}
